package ioperations;

import Book.BookList;
import Book.Books;

import java.util.Scanner;

public class Del implements Ioperation{
    @Override
    public void work(BookList bookList) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入书名：");
        String name = scanner.nextLine();
        int flg = -1;
        for (int i = 0; i < bookList.Size; i++) {
            if (name.compareTo(bookList.books[i].getName()) == 0){
                flg = i;
                break;
            }
        }
        if(flg!=-1){
            for (int i = flg; i < bookList.Size - 1; i++) {
                bookList.books[i] = bookList.books[i+1];
            }
            bookList.books[--bookList.Size] = null;
            System.out.println("删除成功！");
        }else {
            System.out.println("未找到这本书，无法删除！");
        }



    }
}
